import {getSchoolChat, getSchoolChatDetail, sendChatMsg, msgReadState, getStudentList, getStudentInfo} from '@/api/weChatApi'
const weChat = {
    namespaced: true,
    state: {
        studentInfo: localStorage.studentInfo ? localStorage.studentInfo : '',
        chatObj: localStorage.chatObj ? JSON.parse(localStorage.chatObj) : ''
    },
    getters: {
    },
    mutations: {
        setChatObj (state, obj) {
            state.chatObj = obj
            localStorage.chatObj = JSON.stringify(obj)
        }
    },
    actions: {
        GetSchoolChat ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getSchoolChat(params).then(res => {
                    resolve(res)
                })
            })
        },
        GetSchoolChatDetail ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getSchoolChatDetail(params).then(res => {
                    resolve(res)
                })
            })
        },
        SendChatMsg ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                sendChatMsg(params).then(res => {
                    resolve(res)
                })
            })
        },
        MsgReadState ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                msgReadState(params).then(res => {
                    resolve(res)
                })
            })
        },
        GetStudentList ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getStudentList(params).then(res => {
                    resolve(res)
                })
            })
        },
        GetStudentInfo ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getStudentInfo(params).then(res => {
                    state.studentInfo = localStorage.studentInfo = res.gradeName+res.className
                })
            })
        }
    }
}
export default weChat